home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / netobjects / nfx / wizard / WizardPageView.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-20  |  5.7 KB  |  179 lines

  1. package asp.netobjects.nfx.wizard;
  2.  
  3. import asp.netobjects.nfx.util.ExceptionHandler;
  4. import com.sun.java.swing.BorderFactory;
  5. import com.sun.java.swing.JLabel;
  6. import com.sun.java.swing.JPanel;
  7. import java.awt.BorderLayout;
  8. import java.awt.Color;
  9. import java.awt.Container;
  10. import java.awt.FontMetrics;
  11. import java.awt.Insets;
  12. import java.util.Vector;
  13.  
  14. public class WizardPageView extends JPanel {
  15.    private WizardPage dmWizardPage;
  16.    private JPanel dmImagePanel;
  17.    private JPanel dmPagePanel;
  18.    private JPanel dmTextPanel;
  19.    private JPanel dmContentPanel;
  20.    private ImageCanvas dmTextCanvas;
  21.    private int dmPagePanelLeftInset;
  22.  
  23.    public WizardPageView() {
  24.       this.createControls();
  25.    }
  26.  
  27.    public WizardPageView(WizardPage page) {
  28.       this.dmWizardPage = page;
  29.       this.createControls();
  30.    }
  31.  
  32.    protected void createComponents() {
  33.    }
  34.  
  35.    protected void layoutComponents() {
  36.    }
  37.  
  38.    public void createControls() {
  39.       ((Container)this).setLayout(new BorderLayout());
  40.       this.createImagePanel();
  41.       this.dmPagePanel = new JPanel();
  42.       this.dmPagePanel.setLayout(new BorderLayout());
  43.       this.dmPagePanel.setBorder(BorderFactory.createEmptyBorder(0, this.dmPagePanelLeftInset, 0, 0));
  44.       ((Container)this).add("Center", this.dmPagePanel);
  45.       this.createTextCanvas();
  46.       this.dmContentPanel = new JPanel();
  47.       this.dmContentPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
  48.       this.dmPagePanel.add("Center", this.dmContentPanel);
  49.    }
  50.  
  51.    private void createImagePanel() {
  52.       if (this.getModel() != null) {
  53.          if (this.getModel().getIcon() != null) {
  54.             this.dmImagePanel = new JPanel();
  55.             this.dmImagePanel.setLayout(new BorderLayout());
  56.             this.dmImagePanel.setBorder(BorderFactory.createBevelBorder(1, Color.white, Color.gray));
  57.             this.dmImagePanel.add(new JLabel(this.getModel().getIcon()));
  58.             this.dmPagePanelLeftInset = 10;
  59.             if (this.dmPagePanel != null) {
  60.                this.dmPagePanel.setBorder(BorderFactory.createEmptyBorder(0, this.dmPagePanelLeftInset, 0, 0));
  61.             }
  62.  
  63.             ((Container)this).add("West", this.dmImagePanel);
  64.          } else if (this.dmImagePanel != null) {
  65.             ((Container)this).remove(this.dmImagePanel);
  66.             this.dmPagePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
  67.          }
  68.  
  69.       }
  70.    }
  71.  
  72.    private void createTextCanvas() {
  73.       WizardPage model = null;
  74.       if ((model = this.getModel()) != null) {
  75.          if (this.dmTextCanvas != null) {
  76.             ((Container)this).remove(this.dmTextCanvas);
  77.          }
  78.  
  79.          if (model.getBulletText() != null || model.getInfoText() != null) {
  80.             Insets insets = model.getWizard().getView().getInsets();
  81.             int w = 470 - insets.left * 2 - 20 - this.dmPagePanelLeftInset;
  82.             if (model.getIcon() != null) {
  83.                w -= 70;
  84.             }
  85.  
  86.             int h = 66;
  87.             this.dmTextCanvas = new ImageCanvas(this, w, h);
  88.             this.dmTextCanvas.repaint();
  89.             this.dmPagePanel.add("North", this.dmTextCanvas);
  90.          }
  91.       }
  92.    }
  93.  
  94.    public void validate() {
  95.    }
  96.  
  97.    public WizardPage getWizardPage() {
  98.       return this.dmWizardPage;
  99.    }
  100.  
  101.    public WizardPage getModel() {
  102.       return this.dmWizardPage;
  103.    }
  104.  
  105.    public void setModel(WizardPage model) {
  106.       this.dmWizardPage = model;
  107.       this.createImagePanel();
  108.       this.createTextCanvas();
  109.    }
  110.  
  111.    public Wizard getWizard() {
  112.       return this.dmWizardPage != null ? this.dmWizardPage.getWizard() : null;
  113.    }
  114.  
  115.    public ExceptionHandler getExceptionHandler() {
  116.       return this.dmWizardPage.getExceptionHandler();
  117.    }
  118.  
  119.    public void setDirty(boolean set) {
  120.       this.dmWizardPage.setDirty(set);
  121.    }
  122.  
  123.    protected JPanel getContentPanel() {
  124.       return this.dmContentPanel;
  125.    }
  126.  
  127.    public boolean isValid() {
  128.       return true;
  129.    }
  130.  
  131.    private Vector toLines(String s, int width, int maxLines, FontMetrics fm) {
  132.       Vector v = new Vector();
  133.       int start = 0;
  134.       int end = 0;
  135.  
  136.       for(int line = 1; (end = this.clipIndexOf(s, start, width, fm)) != -1; ++line) {
  137.          v.addElement(s.substring(start, start + end));
  138.          start = start + end + 1;
  139.          if (line == maxLines) {
  140.             break;
  141.          }
  142.       }
  143.  
  144.       return v;
  145.    }
  146.  
  147.    private int clipIndexOf(String s, int idx, int width, FontMetrics fm) {
  148.       int tot = 0;
  149.       int start = 0;
  150.       int end = 0;
  151.       String str = s;
  152.       if (idx > 0) {
  153.          str = s.substring(idx);
  154.       }
  155.  
  156.       int swidth = fm.charsWidth(str.toCharArray(), 0, str.length());
  157.       if (swidth <= width) {
  158.          return str.length() - 1;
  159.       } else {
  160.          while((end = str.indexOf(" ", start)) != -1) {
  161.             String token = str.substring(start, end + 1);
  162.             tot += fm.charsWidth(token.toCharArray(), 0, token.length());
  163.             if (tot > width) {
  164.                break;
  165.             }
  166.  
  167.             start = end + 1;
  168.          }
  169.  
  170.          return start - 1;
  171.       }
  172.    }
  173.  
  174.    // $FF: synthetic method
  175.    static Vector access$0(WizardPageView $0, String $1, int $2, int $3, FontMetrics $4) {
  176.       return $0.toLines($1, $2, $3, $4);
  177.    }
  178. }
  179.